<?php
class Perbuatan_notifikasi_model extends MY_Model {
	
    function Perbuatan_notifikasi_model(){
        parent::MY_Model();
        $this->load->database();
        $this->table_name = "perbuatan_notifikasi";
        $this->table_fields = array('perb_notif_id','perb_notif_target_user','perb_notif_type',
        	'perb_notif_post','perb_notif_look','perb_id');
    }
    
    function getNotification($targetUser, $type, $perb_id){
    	$nn = $this->get_where(array(
    		'perb_notif_target_user'=>$targetUser,
    		'perb_notif_type'=>$type,
    		'perb_id'=>$perb_id
    	));
    	$nn = $nn->row();
    	return (array)$nn;
    }
    
    function getNotification_by_id($perb_notif_id){
    	$nn = $this->get_where(array('perb_notif_id'=>$perb_notif_id));
    	$nn = $nn->row();
    	return (array)$nn;
    }
    
    function hasBeenOpened($targetUser, $type, $perb_id){
    	$notif = $this->getNotification($targetUser, $type, $perb_id);
    	
    	//tidak ada datanya, asmusikan sudah dibuka
    	if (!$notif) return true;
    	
    	$notif = (array)$notif;
    	if ($notif['perb_notif_look'] && $notif['perb_notif_look']!='0000-00-00 00:00:00') return true;
    	return false;
    }
    
    function updateOpened($perb_notif_id){
    	return $this->update(array('perb_notif_id'=>$perb_notif_id),array('perb_notif_look'=>date("Y-m-d H:i:s",time())));
    }
}